package com.itheima.api;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.PmsProductCategoryAttributeRelationMapper;
import com.itheima.pojo.db.PmsProductCategoryAttributeRelation;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductCategoryAttributeRelationApiImpl implements PmsProductCategoryAttributeRelationApi {
    @Autowired
    private PmsProductCategoryAttributeRelationMapper pmsProductCategoryAttributeRelationMapper;

    @Override
    public List<PmsProductCategoryAttributeRelation> selectList(Long productCategoryId) {
        return pmsProductCategoryAttributeRelationMapper.selectList(new LambdaQueryWrapper<PmsProductCategoryAttributeRelation>().eq(PmsProductCategoryAttributeRelation::getProductCategoryId, productCategoryId));
    }

    @Override
    public void insertList(List<PmsProductCategoryAttributeRelation> relationList) {
        if (ObjectUtil.isNotEmpty(relationList)) {
            for (PmsProductCategoryAttributeRelation pmsProductCategoryAttributeRelation : relationList) {
                pmsProductCategoryAttributeRelationMapper.insert(pmsProductCategoryAttributeRelation);
            }
        }
    }

    @Override
    public void delete(Long id) {
        pmsProductCategoryAttributeRelationMapper.delete(new LambdaQueryWrapper<PmsProductCategoryAttributeRelation>().eq(PmsProductCategoryAttributeRelation::getProductCategoryId, id));
    }
}
